{% extends 'base.html' %}

{% block title %}添加信息 - www.yunyihuyu.com{% endblock %}

{% block content %}
<div class="container mt-5 mb-5">
    <div class="row">
        <!-- 用户信息栏 -->
        <div class="col-md-3">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">个人信息</h5>
                </div>
                <div class="card-body">
                    <div class="text-center">
                        <div class="mb-3">
                            <i class="fas fa-user-circle fa-3x text-primary"></i>
                        </div>
                        <h5 class="card-title mb-3">{{ user_nickname }}</h5>
                        <p class="card-text">手机号：{{ user_phone }}</p>
                        <p class="card-text">已发布信息：{{ user_product_count }}条</p>
                        <p class="card-text">余额：{{ user_balance }}元</p>
                        {% if user_balance < 1 %}
                        <div class="alert alert-danger">
                            非会员用户，无法发布信息，请充值会员
                        </div>
                        {% endif %}
                        
                        <a href="{% url 'alipay_pay' 100 %}" class="btn btn-primary">充值 100元</a>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 添加信息表单 -->
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">添加信息</h5>
                </div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        
                        {% if form.errors %}
                        <div class="alert alert-danger">
                            请修正以下错误：
                            {% for field in form %}
                                {% for error in field.errors %}
                                    <div>{{ field.label }}: {{ error }}</div>
                                {% endfor %}
                            {% endfor %}
                        </div>
                        {% endif %}
                        {% if messages %}
                            {% for message in messages %}
                                <div class="alert alert-{{ message.tags }} alert-dismissible fade show">
                                    {{ message }}
                                    <!-- <button type="button" class="btn-close" data-bs-dismiss="alert"></button> -->
                                </div>
                            {% endfor %}
                        {% endif %}

                        <div class="mb-3">
                            <label for="{{ form.title.id_for_label }}" class="form-label">标题</label>
                            {{ form.title }}
                        </div>

                        <div class="mb-3">
                            <label for="{{ form.category.id_for_label }}" class="form-label">分类</label>
                            {{ form.category }}
                        </div>


                        <div class="mb-3">
                            <label for="{{ form.description.id_for_label }}" class="form-label">描述</label>
                            {{ form.description }}
                        </div>


                        <div class="mb-3">
                            <label for="{{ form.image.id_for_label }}" class="form-label">图片</label>
                            {{ form.image }}
                        </div>
                        <div class="mb-3">
                            <div class="text-muted">添加信息将扣除1元费用</div>
                        </div>

                        <button type="submit" class="btn btn-primary">提交</button>
                        <a href="{% url 'product_list' %}" class="btn btn-secondary">取消</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
